package fpt.edu.vn.action;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import fpt.edu.vn.dao.TopicsDao;
import fpt.edu.vn.model.Districts;
import fpt.edu.vn.model.Provinces;

/* 
 * InputFuzzySearchAction.java 
 *  
 * 0.1
 * 
 * 10/15/2012 
 *  
 * Copyright notice 
 *  
 * Modification Logs: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  -------------------------------------------------------- 
 *  15-Oct-2012  ThuongND    Create new 
 */
public class InputFuzzySearchAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	// Nội dung các tin đăng
	private List<Object> topicsList;

	// Các tin đã xem
	private List<Object> recentView;

	// Các tin xem nhiều nhất
	private List<Object> mostView;

	// List các thành phố
	private List<Provinces> provinces;
	private List<Districts> districts;
	private TopicsDao dao = new TopicsDao();
	// For SessionAware
	Map<String, Object> session;

	// Hiển thị tên của user
	private String Username;

	private int sortby;

	private int isRentOrShare;

	public String execute() {

		this.isRentOrShare = 1;
		HttpServletRequest request = ServletActionContext.getRequest();
		request.getHeader("VIA");
		String ipAddress = request.getHeader("X-FORWARDED-FOR");
		if (ipAddress == null) {
			ipAddress = request.getRemoteAddr();
		}
		session = ActionContext.getContext().getSession();
		session.put("ipaddress", (String) ipAddress);

		this.provinces = dao.listProvinces();

		this.mostView = dao.listMostView();

		this.recentView = dao.listRecentView(ipAddress);

		this.districts = dao.listDistricts();
		String displayNamess = "";

		session = ActionContext.getContext().getSession();

		if (session.containsKey("displayNamess")) {
			displayNamess = (String) session.get("displayNamess");
		}
		if ("".equals(displayNamess) || displayNamess == null) {
			setUsername(null);
		} else {
			setUsername(displayNamess);
		}
		return SUCCESS;
	}

	public List<Districts> getDistricts() {
		return districts;
	}

	public void setDistricts(List<Districts> districts) {
		this.districts = districts;
	}

	public List<Object> getTopicsList() {
		return topicsList;
	}

	public void setTopicsList(List<Object> topicsList) {
		this.topicsList = topicsList;
	}

	public List<Object> getRecentView() {
		return recentView;
	}

	public void setRecentView(List<Object> recentView) {
		this.recentView = recentView;
	}

	public List<Object> getMostView() {
		return mostView;
	}

	public void setMostView(List<Object> mostView) {
		this.mostView = mostView;
	}

	public List<Provinces> getProvinces() {
		return provinces;
	}

	public void setProvinces(List<Provinces> provinces) {
		this.provinces = provinces;
	}

	public String getUsername() {
		return Username;
	}

	public void setUsername(String username) {
		Username = username;
	}

	public int getIsRentOrShare() {
		return isRentOrShare;
	}

	public void setIsRentOrShare(int isRentOrShare) {
		this.isRentOrShare = isRentOrShare;
	}

	public int getSortby() {
		return sortby;
	}

	public void setSortby(int sortby) {
		this.sortby = sortby;
	}

}
